<!DOCTYPE html>
<html>
	<head>
		{include file="top.tpl"}
		<link rel="stylesheet" type="text/css" href="{$css.url}zTreeStyle/tree.css">  
		<link rel="stylesheet" type="text/css" href="{$css.url}zTreeStyle/zTreeStyle.css"/>
		<link href='{$js.url}plugins/skin/layer.css' rel='stylesheet' type='text/css'/>
		{literal}
        <style>
        	body{font-family: 'Microsoft yahei', 'Helvetica Neue', Helvetica, Arial, sans-serif;padding: 0;}
			.saftyStock{display:none;}
			a{text-decoration: none;}
			select{height: 30px;}
			.lh25{line-height: 25px;}
			.breadcrumb li{font-size: 14px;}
			.breadcrumb li a:hover{background-color: transparent;}
			.my-form{padding: 0 10px;}
			#rule_layer table tr{line-height: 35px;}
			.ztree *{font-size: 13px!important;}
		</style>
		{/literal}
	</head>
<body>
{include file="bread_crumbs.tpl"}
<form method="post" class="my-form" action="./save" name="theForm">
<table class="table-striped table-hover table-bordered" style="width: 100%;margin-top:5px; line-height:25px; font-size:14px;" id="stripe_tb">
    <td colspan="2" ><input type="hidden"  name="rule_id" value="{$backupRule['id']}" /></td>
  	<tr bgcolor="#FFFFFF">
    	<td width="140" align="right">规则名称：</td>
    	<td style="padding:8px;">
			<p>{$backupRule['name']}</p>
		</td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right">简单描述：</td>
    	<td style="padding:8px;">
			<p>{$backupRule['description']}</p>
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right">归类规则：</td>
    	<td style="padding:8px;">
			<div id="sub_rule">
				{foreach from=$filterRule item=oneFilterRule }
					<li style='list-style:none;' id='{$oneFilterRule["filter_type"]}_sub_rule'>
						<input type="hidden" name="rule_item_type[]" value="{$oneFilterRule['filter_type']}" />
						<input type="hidden" name="rule_item_type_operator[]" value="{$oneFilterRule['operator']}" />
						<input type="hidden" name="rule_item_min_num[]" value="{$oneFilterRule['operator_min_param']}" />
						<input type="hidden" name="rule_item_max_num[]" value="{$oneFilterRule['operator_max_param']}" />
						<input type="hidden" name="rule_item_operator_params[]" value="{$oneFilterRule['operator_eq_param']}" />
						<input type="hidden" name="rule_item_desc[]" value="{$oneFilterRule['description']}" />
						{$oneFilterRule['description']}
						<a class="btn btn-primary btn-sm ml5" href="javascript:edit_condition('{$oneFilterRule["filter_type"]}');"><span class="glyphicon glyphicon-eye-open"></span> 查看</a>
					</li>
				{/foreach}				

			</div>
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right">平均销量计算公式：</td>
    	<td style="line-height:25px;padding:8px;">
			{if $backupRule['avg_sales_formula_type']==1}
			    公式1：(30天,15天,7天的平均销量分别为a,b,c,当c最大时,平均销量为c,当c非最大时,平均销量为0.4c+0.6b)
			{elseif  $backupRule['avg_sales_formula_type']==2}
			    公式2: (30天平均销量,当产品上架时间小于30天时,取上架时间段内的平均销量)
			{elseif  $backupRule['avg_sales_formula_type']==3}
			    公式3: ((前15天销量*2+前7天销量*4.3)/60)
			{elseif  $backupRule['avg_sales_formula_type']==4}
			    公式4: (平均销量=前一周日均销量)【备货销量】
			{elseif  $backupRule['avg_sales_formula_type']==5}
			    公式5：(平均销量=(前第一周销量*0.4+前第二周销量*0.6)/7)
			{elseif  $backupRule['avg_sales_formula_type']==6}
			    公式6：(平均销量=前一周日均销量)【真实销量】
			{/if}
		</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right">最小备货量：</td>
    	<td style="padding:8px;">{$backupRule['min_backup']}</td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right">最大备货量：</td>
    	<td style="padding:8px;">
    	基数：
	        {if $backupRule['max_backup_base']==30 }
	             前30天真实销量
	        {elseif $backupRule['max_backup_base']==15 }
	             前15天真实销量
	        {elseif $backupRule['max_backup_base']==7  }
	             前7天真实销量
	        {elseif $backupRule['max_backup_base']== -30 }
	             前30天备货销量
	        {elseif $backupRule['max_backup_base']== -15 }
	             前15天备货销量
	        {elseif $backupRule['max_backup_base']== -7 } 
	             前7天备货销量
	        {elseif $backupRule['max_backup_base']== 1 }
	             1
	        {/if}
    	系数：{$backupRule['max_backup_factor']}</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right">备货天数：</td>
    	<td style="padding:8px;">
        {$backupRule['backup_days_need_backup_days']}
        </td>
  	</tr>
      <tr bgcolor="#FFFFFF">
    	<td align="right">安全库存：</td>
    	<td style="padding:8px;">        
	       {if $backupRule['safe_stock_type']==1}
		       <div class="saftyStock"  >
		           安全库存=基准*系数：
		           基数：
			    	 {if $backupRule['safe_stock_base']==30 }
			             前30天真实销量
			        {elseif $backupRule['safe_stock_base']==15 } 
			             前15天真实销量
			        {elseif $backupRule['safe_stock_base']==7  }
			             前7天真实销量
			        {elseif $backupRule['safe_stock_base']== -30 }
			             前30天备货销量
			        {elseif $backupRule['safe_stock_base']== -15 }
			             前15天备货销量
			        {elseif $backupRule['safe_stock_base']== -7 } 
			             前7天备货销量
			        {elseif $backupRule['safe_stock_base']== 1 }
			             1
			        {/if}

		    	系数：{$backupRule['safe_stock_factor']}
		        </div>
	       	 {elseif $backupRule['safe_stock_type']==2}
			      {$backupRule['safe_stock_need_backup_days']}
             {/if}
      </td>
  	</tr>
	<tr bgcolor="#FFFFFF">
    	<td align="right">是否启用：</td>
    	<td style="padding:8px;">
			{if $backupRule['is_enable']=='2'}停用{/if}
			{if $backupRule['is_enable']=='1'}启用{/if}
		    {if $backupRule['is_enable']=='1'}
			生效时间：{$backupRule['start_date']}截止时间：{$backupRule['end_date']}
    		{/if}
		</td>
  	</tr>
  	<tr bgcolor="#FFFFFF">
    	<td align="right">优先级别：</td>
    	<td style="padding:8px;">
    	 {$backupRule['priority']}
    	<span style='color:red'>(优先级别从高到低顺序依次是1,2,3,4,5)</span>
    	</td>
  	</tr>
	<tr bgcolor="#FFFFFF">
  	  <td align="right">适用仓库：</td>
  	  <td>
         {$applyWarehouse}
       </td>
    </tr>    
    <tr bgcolor="#FFFFFF">
    	<td align="right"> </td>
    	<td style="color:#666666;">
			备注说明：<br />
			1.备货数量=平均销量*备货天数<br />
			2.需求C：当需求A大于0时，需求C等于备货数量，当需求A等于0时，需求C=备货数量－可用库存<br />
			3.需求C：当需求C小于最小备货量  且 需求C小于等于（备货数量/2）时，则不产生需求C
		</td>
  	</tr>
</table>
<div style="padding-left: 140px;margin-top: 15px;">
	<input type="button" value="返回" class="btn btn-default btn-md" onclick="location.href='/backup/rule/list'" />
</div>
</form>

<div id="rule_layer" style="display:none;">
	<div style="padding:20px;font-size: 13px;">
		<table>
			<tr>
				<td width="80" align="left">筛选条件：</td>
				<td>
					<select id="type" name="type" onchange="show_condition()">
					   <option value="product_level">产品等级</option>
						<option value="product_category">产品分类</option>
						<option value="product_sales">前30天历史销量</option>
						<option value="product_price">产品进货价</option>
						<option value="product_stock">库存</option>
						<option value="product_state">货源状态</option>
						<option value="recmd_level">产品推荐等级</option>
						<option value="chinabrands">chinabrands是否上架</option>
						<option value="min_stock">最小库存</option>
						<option value="live_age">产品生命周期</option>
					</select>
				</td>
			</tr>
			
			<tr>
				<td valign="top" align="left">条件设定：</td>
				<td>
					<div class="condition_layer" id="product_level_layer" style="padding:3px;">
						{foreach from=$allProductGrade item=productGrade }
							<li style="list-style:none;">
								<input disabled type="checkbox" name="cbo_product_level" value="{$productGrade['id']}" id="cbo_level_{$productGrade['id']}" title="{$productGrade['name']}" {if in_array({$productGrade['id']},$filterRule['product_level']['operator_eq_params'])}checked{/if}/><label for="cbo_level_{$productGrade['id']}" class="ml5">{$productGrade['name']}</label>
							</li>
						{/foreach}
		
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返 回  " />
						</div>
					</div>
					
					<!--------------------------- 产品分类 ------------------------>
					<div class="condition_layer" id="product_category_layer" style="display:none;">
						<input type="hidden" id="rid" value="0" />
						<div>
							<ul id="all_product_category" class="ztree"></ul>
						</div>

						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!--------------------------- 前30天历史销量 ------------------------>
					<div class="condition_layer" id="product_sales_layer" style="padding:3px; display:none;" {$_product_sales_operator=($filterRule['product_sales']['operator']|default:'')}>
						<input type="radio" name="rdo_product_sales" id="rdo_sales_1" value="lt" 
						       {if $_product_sales_operator=='lt'} checked {/if} 
						       onclick="show_sub_type('rproduct_sales_cls','sales_lt')" /><label for="rdo_sales_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_sales" id="rdo_sales_2" value="gt" 
						       {if $_product_sales_operator=='gt'} checked {/if} 
						       onclick="show_sub_type('rproduct_sales_cls','sales_gt')"  /><label for="rdo_sales_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_sales" id="rdo_sales_3" value="between" 
						       {if $_product_sales_operator=='between'} checked {/if} 
						       onclick="show_sub_type('rproduct_sales_cls','sales_in')" /><label for="rdo_sales_3" class="ml5">介于两个数量之间</label>
						<div class="rproduct_sales_cls lh25" id="sales_lt_layer" {if $_product_sales_operator!='lt'} style="display:none;"{/if}>
							前30天历史销量小于<input type="text" name="min_sales" id="min_sales" size="6" value="{if $_product_sales_operator=='lt'}{$filterRule['product_sales']['operator_min_param']}{/if}"/>个
						</div>
						<div class="rproduct_sales_cls lh25" id="sales_gt_layer" {if $_product_sales_operator!='gt'} style="display:none;"{/if}>
							前30天历史销量大于等于<input type="text" name="max_sales" id="max_sales" size="6" value="{if $_product_sales_operator=='gt'}{$filterRule['product_sales']['operator_max_param']}{/if}" />个
						</div>
						<div class="rproduct_sales_cls lh25" id="sales_in_layer" {if $_product_sales_operator!='between'} style="display:none;"{/if}>
							前30天历史销量介于<input type="text" name="in_min_sales" id="in_min_sales" size="6" value="{if $_product_sales_operator=='between'}{$filterRule['product_sales']['operator_min_param']}{/if}" />个(包含)
								<input type="text" name="in_max_sales" id="in_max_sales" size="6" {if $_product_sales_operator=='between'}{$filterRule['product_sales']['operator_max_param']}{/if} />个(不包含)之间
						</div>

						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!------------------------- 产品进货价 -------------------------->
					<div class="condition_layer" id="product_price_layer" style="padding:3px; display:none;" {$_product_price_operator=($filterRule['product_price']['operator']|default:'')} >
						<input type="radio" name="rdo_product_price" id="rdo_price_1" value="lt" {if $_product_price_operator=='lt'} checked {/if}  onclick="show_sub_type('product_price_cls','price_lt')" /><label for="rdo_price_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_price" id="rdo_price_2" value="gt" {if $_product_price_operator=='gt'} checked {/if}  onclick="show_sub_type('product_price_cls','price_gt')" /><label for="rdo_price_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_price" id="rdo_price_3" value="between" {if $_product_price_operator=='between'} checked {/if}  onclick="show_sub_type('product_price_cls','price_in')" /><label for="rdo_price_3" class="ml5">介于两个数量之间</label>
						<div class="product_price_cls lh25" id="price_lt_layer" {if $_product_price_operator!='lt' }style="display:none;"{/if}>
							产品进货价小于<input type="text" name="min_price" id="min_price" size="6" {if $_product_price_operator=='lt'}{$filterRule['product_price']['operator_min_param']}{/if} />元
						</div>
						<div class="product_price_cls lh25" id="price_gt_layer" {if $_product_price_operator!='gt' }style="display:none;"{/if}>
							产品进货价大于等于<input type="text" name="max_price" id="max_price" size="6" value="{if $_product_price_operator=='gt'}{$filterRule['product_price']['operator_max_param']}{/if}"  />元
						</div>
						<div class="product_price_cls lh25" id="price_in_layer" {if $_product_price_operator!='between' }style="display:none;"{/if}>
							产品进货价介于<input type="text" name="in_min_price" id="in_min_price" size="6" value="{if $_product_price_operator=='between'}{$filterRule['product_price']['operator_min_param']}{/if}" />元(包含)
								<input type="text" name="in_max_price" id="in_max_price" size="6" value="{if $_product_price_operator=='between'}{$filterRule['product_price']['operator_max_param']}{/if}" />元(不包含)之间
						</div>
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!--------------------------- 库存 ------------------------>
					<div class="condition_layer" id="product_stock_layer" style="padding:3px; display:none;" {$_product_stock_operator=($filterRule['product_stock']['operator']|default:'')} >
						<input type="radio" name="rdo_product_stock" id="rdo_stock_1" value="lt" {if $_product_stock_operator=='lt'} checked {/if} onclick="show_sub_type('product_stock_cls','stock_lt')" /><label for="rdo_stock_1" class="ml5">小于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_stock" id="rdo_stock_2" value="gt" {if $_product_stock_operator=='lt'} checked {/if} onclick="show_sub_type('product_stock_cls','stock_gt')" /><label for="rdo_stock_2" class="ml5">大于指定数量</label>&emsp;
						<input type="radio" name="rdo_product_stock" id="rdo_stock_3" value="between" {if $_product_stock_operator=='lt'} checked {/if}  onclick="show_sub_type('product_stock_cls','stock_in')" /><label for="rdo_stock_3" class="ml5">介于两个数量之间</label>
						<div class="product_stock_cls lh25" id="stock_lt_layer" {if $_product_stock_operator!='lt'}style="display:none;"{/if}>
							库存数量小于<input type="text" name="min_stock" id="min_stock" size="6" value="{if $_product_stock_operator=='lt'}{$filterRule['product_stock']['operator_min_param']}{/if}" />个
						</div>
						<div class="product_stock_cls lh25" id="stock_gt_layer" {if $_product_stock_operator!='gt'}style="display:none;"{/if}>
							库存数量大于等于<input type="text" name="max_stock" id="max_stock" size="6" value="{if $_product_stock_operator=='gt'}{$filterRule['product_stock']['operator_max_param']}{/if}"  />个
						</div>
						<div class="product_stock_cls lh25" id="stock_in_layer" {if $_product_stock_operator!='between'}style="display:none;"{/if}>
							库存数量介于<input type="text" name="in_min_stock" id="in_min_stock" size="6" value="{if $_product_stock_operator=='between'}{$filterRule['product_stock']['operator_min_param']}{/if}" />个(包含)
								<input type="text" name="in_max_stock" id="in_max_stock" size="6" value="{if $_product_stock_operator=='between'}{$filterRule['product_stock']['operator_max_param']}{/if}" />个(不包含)之间
						</div>
						
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!---------------------------货源状态------------------------>
					<div class="condition_layer" id="product_state_layer" style="padding:3px; display:none;" {$_product_state_operator=($filterRule['product_state']['operator']|default:'')}  >
						<input type="checkbox" name="cbo_product_state" id="cbo_state_1" value="1" title="正常" {if $_product_state_operator && in_array(1,$filterRule['product_state']['operator_eq_params']) } checked {/if} /><label for="cbo_state_1" class="ml5">正常</label>&emsp;
						<input type="checkbox" name="cbo_product_state" id="cbo_state_2" value="2" title="断货" {if $_product_state_operator && in_array(2,$filterRule['product_state']['operator_eq_params']) } checked {/if} /><label for="cbo_state_2" class="ml5">断货</label>&emsp;
						<input type="checkbox" name="cbo_product_state" id="cbo_state_3" value="3" title="停产" {if $_product_state_operator && in_array(3,$filterRule['product_state']['operator_eq_params'])} checked {/if} /><label for="cbo_state_3" class="ml5">停产</label>
						
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!---------------------------推荐等级------------------------>
					<div class="condition_layer" id="recmd_level_layer" style="padding:3px; display:none;" {$_recmd_level_operator=($filterRule['recmd_level']['operator']|default:'')}  >
		
						<input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_a" value="a" title="a"  {if $_recmd_level_operator && in_array("'a'",$filterRule['recmd_level']['operator_eq_params']) } checked {/if} /><label for="" class="ml5">a</label>&emsp;
                        <input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_b" value="b" title="b" {if $_recmd_level_operator && in_array("'b'",$filterRule['recmd_level']['operator_eq_params']) } checked {/if} /><label for="" class="ml5">b</label>&emsp;
						<input type="checkbox" name="cbo_recmd_level" id="cbo_recmd_level_c" value="c" title="c" {if $_recmd_level_operator && in_array("'c'",$filterRule['recmd_level']['operator_eq_params']) } checked {/if} /><label for="" class="ml5">c</label>&emsp;
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					
					<!--------------------------CHINABRAND是否同步------------------------>
					<div class="condition_layer" id="chinabrands_layer" style="padding:3px; display:none;">
						<input type="checkbox" name="cbo_chinabrands" id="cbo_chinabrands_1" value="1" title="是" /><label for="cbo_chinabrands_1" class="ml5">是</label>&emsp;
						<input type="checkbox" name="cbo_chinabrands" id="cbo_chinabrands_2" value="0" title="否" /><label for="cbo_chinabrands_2" class="ml5">否</label>&emsp;
						
						<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>
					</div>
					<!-------------------------- 产品生命周期 ------------------------>
					<div class="condition_layer" id="live_age_layer" style="padding:3px; display:none;">
                    
                     <label for="live_age1"><input id="live_age1" name="live_age" type="checkbox" value="成长期" title="成长期" checked /> 成长期</label>
                     <label for="live_age2" class="ml10"><input id="live_age2" name="live_age" type="checkbox" value="成熟期" title="成熟期" checked /> 成熟期</label>
                     <label for="live_age3" class="ml10"><input id="live_age3" name="live_age" type="checkbox" value="衰败期" title="衰败期" checked /> 衰败期</label>
                     <label for="live_age4" class="ml10"><input id="live_age4" name="live_age" type="checkbox" value="其他时期" title="其他时期" checked /> 其他时期</label>
      					<div style="line-height:50px;">
							<input type="button" class="btn_cancel_cls btn btn-default" value="  返回  " />
						</div>           
                    </div>
				</td>
			</tr>
		</table>
	</div>
</div>
{include file='foot.tpl'}
<script>
{literal}
$(function(){
	$('.date_start').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	}).on('changeDate', function(ev){
        $(".date_end").val("").datetimepicker('setStartDate',$(this).val());
    });
    $('.date_end').datetimepicker({
	    format: "yyyy-mm-dd",
        minView:2,
        autoclose: true,
        todayHighlight: false
	});
    
    $('#rule_layer input[type="text"], #rule_layer select, #rule_layer input[type="radio"],#rule_layer input[type="checkbox"]').attr("disabled", "false");
})
{/literal}
</script>
<script src="{$js.url}backup/backup_rule.js"></script>
<script src="{$js.url}app_widget/product_catalog.js"></script>
{literal}
<script>

var productCatalog=new AppProductCatalog("all_product_category");
var _hasCheckedCategory=$("#product_category_sub_rule > input[name='rule_item_operator_params[]']").val();
if(_hasCheckedCategory){
   productCatalog.init(_hasCheckedCategory.split(','));
}else{
   productCatalog.init();
}

function display_date(val)
{
	if(val==1)
	{
	    document.getElementById('date').style.display='none';	
	}else if(val==2){
		document.getElementById('date').style.display='';
	}
}
{/literal}
</script>
</body>
</html>